<template>
    <div class="goodlist">
        <!-- <router-link class="gooditem" v-for="item in goodList" :key="item.index" :to="'/home/goodsinfo/'+item.id" tag="div">
            <img :src="item.src" alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                   <span class="now">{{item.newPrice}}</span>
                   <span class="old">{{item.oldPrice}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{item.num}}件</span>
                </p>
            </div>
        </router-link> -->
        <div class="gooditem" v-for="item in goodList" :key="item.index" @click="goDetail(item.id)">
            <img :src="item.src" alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                   <span class="now">{{item.newPrice}}</span>
                   <span class="old">{{item.oldPrice}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{item.num}}件</span>
                </p>
            </div>
        </div>
        <mt-button type="danger" size="large" @click="addMore">加载更多</mt-button>
    </div>
</template>


<script>
// import Toast from 'mint-ui'
export default {
    data(){
        return {
            // 往自己组建内部挂载私有数据
            pageIndex:1,
            goodList:[
                {id:1,
                title:'小米6X 全网通 4GB+64GB 曜石黑 移动联通电信4G手机 双卡双待 智能手机',
                src:'https://img10.360buyimg.com/n7/jfs/t18772/89/1863054684/170815/d28ecae1/5adca3deN76bb61cb.jpg',
                num:690,
                oldPrice:'￥1798',
                newPrice:'￥1898'},
                {id:2,
                title:'Apple iPhone X (A1865) 64GB 深空灰色 移动联通电信4G手机',
                src:'https://img13.360buyimg.com/n7/jfs/t10675/253/1344769770/66891/92d54ca4/59df2e7fN86c99a27.jpg',
                num:290,
                oldPrice:'￥6499',
                newPrice:'￥6898'},
                {id:3,
                title:'Z36GB+64GB极光蓝性能实力派全面屏游戏手机',
                src:'https://img14.360buyimg.com/n7/jfs/t27616/251/1425719819/224805/20c2401e/5bc831fdN61f8d9d2.jpg',
                num:290,
                oldPrice:'￥1899',
                newPrice:'￥2098'}
            ]
        }
    },
    created(){
        // getGoodList()
    },
    methods:{
        // 获取商品列表
        getGoodList(){
            this.$http.get('url/'+this.pageIndex).then(res=>{
                if(res.body.status==0){
                //    this.goodList = res.body.message;
               this.goodList = this.goodList.concat(res.body.message);
                }
            })
        },
        addMore(){
            this.pageIndex++;
            // this.getGoodList();
            // Toast('xixi')
        },
        // 使用js的形式进行路由导航
        goDetail(id){
            // 一定要区分this.$route 路由参数对象，所有路由中的参数，params query
            // this.$router是一个路由导航对象，用它可以方便的使用js代码实现路由的前进、后退、跳转到新的url地址
        
        // 1、最简单的
        this.$router.push('/home/goodsinfo/'+id)
        // 2、第二种
        // this.$router.push({ path: '/home/goodsinfo/'+id })
        // 2、第三种
    //    this.$router.push({ name: 'goodsinfo', params: { id }})
        }
    }
}
</script>

<style lang="less" scoped>
.goodlist{
    display: flex;
    flex-wrap: wrap;
    padding: 7px;
    justify-content: space-between;
    .gooditem{
        width: 48%;
        border: 1px solid #ccc;
        box-shadow: 0 0 8px #ccc;
        margin: 3px;
        padding: 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 293px;
        img{
            width: 100%
        }
        .title{
            font-size: 14px;
        }
        .info{
            background-color: #eee;
            padding: 3px;
            p{
                margin: 0;
            }
            .price{
                .now{
                    color: red;
                    font-size: 16px;
                    font-weight: bold;
                }
                .old{
                    text-decoration: line-through;
                    font-size: 12px;
                    margin-left: 10px;
                }
            }
            .sell{
                display: flex;
                justify-content: space-between;
                font-size: 12px;
            }
        }
    }

}
</style>


